﻿Ext.define('Sys.controller.SysTreeMenu', {
    extend: 'Ext.app.Controller',
    views: ['SysTreeMenu.List'],
    init: function () {
        this.control({
            'SysTreeMenuList > treepanel': {
                itemclick: this.itemclick
            }
        });
    },
    itemclick: function (tree, record, item, index, e, eOpts) {
        if (!record.get('leaf') || !record.raw
						|| Ext.isEmpty(record.raw.ClassID))
            return false;
        if (record.raw.panel && record.raw.panel.getEl()) {
            record.raw.panel.show();
            return false;
        }
        //        debugger;
        var _con = record.raw.ClassID;
        var controller = Sys.app.controllers.get(_con);
        if (!controller) {
            controller = Sys.app.getController(record.raw.ClassID);
//            controller.init();
        }
        //        debugger;

        record.raw.panel = undefined;
        record.raw.panel = controller.getView(controller.views[0]).create({
            closable: true,
            title: record.get('text'),
            iconCls: record.get('iconCls')
        });
        Ext.getCmp('tabpanel').add(record.raw.panel).show();
    }
});